import React from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import {actions} from '../../reducers'
import {actions as ProjectAction} from '../../reducers/project'
import moment from 'moment'
import Resource from '../../components/resource'
import utils from '../../common/utils'

class Schedule extends React.Component {
	constructor(props) {
		super(props)
	  }

	  componentDidMount() {
		let type = utils.getQueryString('type', window.location.search),
				id = utils.getQueryString('id', window.location.search),
				project_id = utils.getQueryString('project_id', window.location.search)
		this.props.get_project_detail(id, type)
	  }

    render() {
		const {project_milestone, project_progress} = this.props.project
        return(
            <div class="tabs-1">
				<div class="msg">
					<div class="msg2">
					{
						project_milestone[0] ?
						project_milestone.map((x, i)=> 
							<dl key={x.id}>
								<dt>{moment(x.expect_at).format('MM/DD')}</dt>
								<dd>
									<div class="s1">{i+1}</div>
									<div class="s2">{x.title}</div>
								</dd>
							</dl>
						) :
						<p>未设置项目里程碑</p>
					}
		
						{/* <dl class="first">
							<dt>12/30</dt>
							<dd>
								<div class="s1">3</div>
								<div class="s2">产品支付</div>
							</dd>
						</dl> */}
					</div>
				</div>
				<div class="hr"></div>
				<div class="data-list">
				{
					project_progress[0]&&
					project_progress.map( x =>
						<div class="list-box" key={x.id}>
							<div class="hd-msg">
								<div>
									<span>发布者：</span>
									<em>{x.user&&x.user.nickname}</em>
								</div>
								<div>{moment(x.created_at).format('YYYY-MM-DD')}</div>
							</div>
							<div class="list">
								{/* <div>一、项目说明</div> */}
								<p>{x.content}</p>
							</div>
							<Resource resource={x.project_resource}/>
						</div>
					)
				}

				</div>
			</div>

        )
    }
}
function mapStateToProps(state) {
	return {
		project: state.project.detail,
	}
}

function mapDispatchToProps(dispatch) {
	return  {
		get_project_detail: bindActionCreators(ProjectAction.get_detail, dispatch),
	}
}

export default connect(
	mapStateToProps,
	mapDispatchToProps
)(Schedule)